﻿Imports System.Web
Imports System.Web.Services
Imports System.Drawing.Imaging
Imports System.Web.SessionState
Imports CaptchaDLL
Imports MeoTom.Core

Public Class CapchaImage
    Implements IReadOnlySessionState, System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim objUtil As New Utilities.Common
        If Not objUtil.GetSession("CapchaImageText") = "" Then
            Dim ci As New CaptchaImage(context.Session("CaptchaImageText").ToString(), 100, 25, "Arial", System.Drawing.Color.FromArgb(255, 255, 255), System.Drawing.Color.FromArgb(163, 7, 7))
            context.Response.Clear()
            context.Response.ContentType = "image/jpeg"
            ci.Image.Save(context.Response.OutputStream, ImageFormat.Jpeg)
            ci.Dispose()
        Else
            'context.Session("CaptchaImageText") = CaptchaImage.GenerateRandomCode(CaptchaType.AlphaNumeric, 4)

            Dim ci As New CaptchaImage(context.Session("CaptchaImageText").ToString(), 100, 25, "Arial", System.Drawing.Color.FromArgb(255, 255, 255), System.Drawing.Color.FromArgb(163, 7, 7))
            context.Response.Clear()
            context.Response.ContentType = "image/jpeg"
            ci.Image.Save(context.Response.OutputStream, ImageFormat.Jpeg)
            ci.Dispose()
        End If
        objUtil = Nothing
    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class